package com.team11.server.controller.teacher;

import com.team11.server.pojo.CFiles;
import com.team11.server.service.impl.CFilesServiceImpl;
import com.team11.server.util.file.FileDownUtil;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import javax.annotation.Resource;
import javax.servlet.http.HttpServletResponse;


/**
 * <p>
 * 前端控制器
 * </p>
 *
 * @author pjc
 * @since 2021-06-17
 */
@CrossOrigin
@Slf4j
@RestController
@Api(tags = "教师接口")
public class TeacherCFilesController {
    @Resource
    private CFilesServiceImpl icFilesService;

    @ApiOperation(value = "文件下载")
    @GetMapping("/download/{fId}")
    public void download(@PathVariable("fId") int fId, HttpServletResponse response) {
        CFiles file = icFilesService.getById(fId);
        if (file != null) {
            String path = file.getCFile();
            log.info("download file path is:{}", path);
            FileDownUtil.download(path, response);
        }
    }
}
